package logic.med.ui
{
	import common.core.GSprite;
	import common.manager.GScene;
	import common.manager.GUI;
	import common.manager.Resource;
	
	import fl.controls.Button;
	import fl.controls.TextInput;
	import fl.events.ComponentEvent;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import logic.def.Def;
	import logic.med.scene.PreScene;
	import logic.med.scene.SceneA;

	public class Login extends GSprite
	{
		static public const NAME:String = "Login";
		
		private var m_login : Sprite;
		
		private var m_txtUserName : TextInput;
		private var m_txtPssWord : TextInput;
		
		private var m_btnLogin : Button;
		
		public function Login()
		{
			var loginClass : Class = Resource.getClass(NAME,Def.Facade)
			m_login = new loginClass;	
			
			m_txtPssWord = m_login["TxtPassWord"];
			m_txtUserName = m_login["TxtUserName"];
			m_btnLogin = m_login["BtnLogin"];
			
			m_txtPssWord.displayAsPassword = true;
			
			this.addChild(m_login);
			
			GUI.add(Login.NAME,this);
			GUI.setAlgin(Login.NAME,GUI.ALIGN_MIDDLE);
			
			m_txtPssWord.addEventListener(ComponentEvent.ENTER,onEnterKey);
			m_txtUserName.addEventListener(ComponentEvent.ENTER,onEnterKey);
			m_btnLogin.addEventListener(MouseEvent.CLICK,onClickLoginBtn);
		}
		
		private function onClickLoginBtn(evt : MouseEvent) : void
		{
			destory();
		}
		
		private function  onEnterKey(evt : ComponentEvent) : void
		{
			destory();
		}
		
		public function destory() : void
		{
			m_txtPssWord.removeEventListener(ComponentEvent.ENTER,onEnterKey);
			m_txtUserName.removeEventListener(ComponentEvent.ENTER,onEnterKey);
			m_btnLogin.removeEventListener(MouseEvent.CLICK,onClickLoginBtn);
			
			GUI.close(NAME);
			GScene.clearScene(PreScene.NAME);
			GScene.openScene(SceneA.NAME);
		}
	}
}